/**
 * 
 */
package playGround.border;

import java.util.List;

import playGround.square.Square;

import be.kuleuven.cs.som.annotate.Basic;
import be.kuleuven.cs.som.annotate.Immutable;
import be.kuleuven.cs.som.annotate.Raw;

/**
 * @author Niels Claeys, Maarten Christiaen
 * @version 2.2
 */
public class Door extends Border {
	
	/**
	 * the variable that checks if the door is open.
	 */
	private boolean isOpen;
	
	/**
	 * this method initializes a door
	 * @post the door is initialized as a border with slippery set to false
	 * 			| super(false)
	 */
	@Raw
	public Door() {
		super(false);
	}
	/**
	 * This method can change the state of the door
	 * @post opens the door if it was closed
	 * 			| if(this.getIsOpen() == false)
	 * 			| new.getIsOpen()==true
	 * @post closes the door if it was open
	 * 			| if(this.getIsOpen()==true
	 * 			| new.getIsOpen==false
	 */
	public void changeState(){
		if(this.getIsOpen() == false){
			List<Square> seperatedSquares = super.getSeperatedSquares();
			Square square1=seperatedSquares.get(0);
			this.setIsOpen(true);
			square1.resolveAreaImbalance(seperatedSquares.get(1));
		}
		else
			this.setIsOpen(false);
	}
	
	/**
	 * This method returns whether or not the door is open
	 * @return whether or not the door is open
	 */
	@Basic
	public boolean getIsOpen(){
		return this.isOpen;
	}
	/**
	 * this method sets the door to isOpen
	 * @param isOpen to open or close the door
	 * @post the door is set to isOpen
	 * 			| new.getIsOpen() == isOpen
	 */
	public void setIsOpen(boolean isOpen){
		this.isOpen = isOpen;
	}

	/**
	 * This method says that a door cannot be on the floor
	 * @return false because it cannot be on the floor
	 * 		| result == false
	 */
	@Override @Immutable
	public boolean canBeOnFloor() {
		return false;
	}
	/**
	 * This method says that the door can be opened or closed.
	 * @return true if there is a square on the other side where you can go to
	 * 		|if(super.getNbSquares()==2)
	 * 		| then result == true
	 */
	@Override
	public boolean canBeOpenedOrClosed() {
		if(super.getNbSquares()==2)
			return true;
		return false;
	}
	/**
	 * This method open or closes the door if it is possible to open or close it
	 * @post open or closes it
	 * 		| if(canBeOpenedOrClosed())
	 * 		| then changeState()
	 */
	@Override
	public void openOrClose() {
		if(canBeOpenedOrClosed())
			changeState();
	}
	/**
	 * This method says whether or not you can pass through here
	 * @return
	 * 			| result == getIsOpen()
	 */
	@Override
	public boolean canPassThrough(){
		return this.isOpen;
	}
	
}
